import { generateXML } from './XML/main'

export function getOutPathFCP(pathObject) {
  const name = decodeURI(pathObject.name)
  return path.resolve(pathObject.dir, `[autocut.video]${name}.fcpxmld`)
}

export class FCPXMLDExporter {
  constructor(pathObject, mediaInfo, fragmentArray) {
    this.pathObject = pathObject
    this.mediaInfo = mediaInfo
    this.fragmentArray = fragmentArray
  }
  async download() {
    const pairs = this.fragmentArray
    const xml = generateXML(this.pathObject, this.mediaInfo, pairs)

    console.log('fcp项目xml', xml)
    // vlevin @ 2023-01-16 浏览器无法向特定目录中写文件，仅作参考
    // vlevin @ 2023-01-16 对FCP而言，需要将文件名改为Info.fcpxml，并放在名为xxx.fcpxmld的文件夹中
    // const outFilePath = getOutPathFCP(this.pathObject)
    // fse.ensureDir(outFilePath)
    // fse.writeFileSync(path.resolve(outFilePath, 'Info.fcpxml'), xml)
    // console.log(`已保存${outFilePath}到当前目录`)
  }
}
